package cn.bitkit.mybatis.builder;

import cn.bitkit.mybatis.base.BaseSqlBuilder;
import cn.bitkit.mybatis.CriteriaHandler;
import cn.bitkit.mybatis.entity.EntityClass;

import java.util.Map;
import java.util.StringJoiner;

/**
 * @author changbo
 */
public class SelectCountBuilder implements BaseSqlBuilder {

    @Override
    public boolean supportLinkTable() {
        return true;
    }

    @Override
    public String build(EntityClass entityClass, Map<String, Object> paramMap) {
        StringJoiner sql = new StringJoiner(" \n");
        sql.add("SELECT count(0)");
        sql.add("FROM " + CriteriaHandler.getFrom(entityClass, paramMap));
        sql.add("<where>");
        sql.add(CriteriaHandler.getWhereSql(paramMap));
        sql.add("</where>");
        return sql.toString();
    }

}
